package com.zerui.manager.app.openplan.executer;

import com.alibaba.cola.catchlog.CatchAndLog;
import com.alibaba.cola.exception.BizException;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.zerui.cola.dto.Response;
import com.zerui.manager.openplan.OpenPlan;
import com.zerui.manager.openplan.domainservice.OpenPlanRepository;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author wh
 * @create_time 2023-09-02 10:15
 */
@Component
@CatchAndLog
public class OpenPlanEnableCmdExe {

    @Resource
    private OpenPlanRepository openPlanRepository;

    public Response execute(Long id) {
        OpenPlan openPlan = openPlanRepository.selectById(id);
        if(ObjectUtils.isEmpty(openPlan)){
            throw new BizException("开门计划不存在");
        }
        return openPlan.getAccept() ? openPlanRepository.disable(openPlan) :
                openPlanRepository.enable(openPlan);
    }
}
